package com.example.newbook.common;

import lombok.*;

import java.io.Serializable;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class JsonResult<T> implements Serializable {

    private int code;
    private String msg;
    private T data;


    public static <T> JsonResult ok(T data){
        return new JsonResult(200,"success",data);
    }


    public static <T> JsonResult success(String msg){
        return new JsonResult(0,msg,null);
    }


    public static <T> JsonResult fail(String msg){
        return new JsonResult(-1,msg,null);
    }


    public static <T> JsonResult error(String msg){
        return new JsonResult(500,msg,null);
    }

    public static <T> JsonResult error(){
        return new JsonResult(500,"系统繁忙，请稍后再试",null);
    }

}
